// $Id: main.cpp 479 2008-05-28 00:25:03Z agjermun $
// Beskrivelse
//
// ml278
// Copyright (C) 2008 Bjørn Øivind Bjørnsen, Aleksander Gjermundsen, Knut Andre Tidemann, Thomas Hansen
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

// Custom index-page for Doxygen
/*! \mainpage ml278 documentation
 *
 * \section into_sec Introduction
 *
 * ml278 is a moonlander simulator/game/techdemo developed as a student project.
 *
 * \section install_sec Installation
 *
 * \subsection step1 1. Get the sourcecode from svn or download a build (skip to step 5).
 * \subsection step2 2. Make sure all dependencies are installed.
 * \subsection step3 3. Change directory to "m278" in trunk.
 * \subsection step4 4. Run "cmake .", then "make".
 * \subsection step5 5. Run the executable in the "src/"-folder: "./ml278".
 */


#include "application.h"
#include <cstring>
#include <iostream>

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#endif

//INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
//#else
/**
 * constructor with shape type and a position vector
 * @param argc the number of passed command line arguments
 * @param argv array of strings with the command line arguments
*/
int main(int argc, char **argv)
{
	// Create application object
	Application *app = new Application();

	// Command line argument handling
	for (int i = 1;i < argc;i++)
	{
		if (strcmp(argv[i], "--no-keyboard") == 0)
		{
			app->setKeyboardInput(false);
		}
		else if (strcmp(argv[i], "--no-mouse") == 0)
		{
			app->setMouseInput(false);
		}
		else if (strcmp(argv[i], "--no-joystick") == 0)
		{
			app->setJoystickInput(false);
		}
		else if (strcmp(argv[i], "--no-input") == 0)
		{
			app->setKeyboardInput(false);
			app->setMouseInput(false);
			app->setJoystickInput(false);
		}

		// Print help/usage information
		else if (strcmp(argv[i], "--help") == 0)
		{
			cout << "ml278 - 3D Planetary Surveyor" << endl;
			cout << "usage: ml278 [arguments]" << endl << endl;
			cout << "Arguments:" << endl;
			cout << "\t--no-keyboard\t\tDisables keyboard input (default: on)" << endl;
			cout << "\t--no-mouse\t\tDisables mouse input (default: on)" << endl;
			cout << "\t--no-joystick\t\tDisables joystick input (default: on)" << endl;
			cout << "\t--no-input\t\tDisables all input (mouse,keyboard and joystick, all default: on)" << endl;
			// Exit after printing help to console
			return 0;
		}
	}

	try
	{
		app->go();
	}
	catch (Exception& e)
	{
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
		MessageBox(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
		fprintf(stderr, "An exception has occurred: %s\n",
		        e.getFullDescription().c_str());
#endif
		// Log exception
		String str("*** An exception has occurred: ");
		str += e.getFullDescription().c_str();
		LogManager::getSingletonPtr()->logMessage(str);
	}

	delete app;

	return 0;
}
